<i><%@page language="java" import="java.util.*" pageEncoding="UTF-8"%>
	<!DOCTYPE html>
	<html>
<head>
<meta charset="UTF-8">
<title>玩/艺术/学乐/达人-作品表 编辑页面</title>
<meta
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
	name="viewport">
<jsp:include page="../com/header.jsp"></jsp:include>
<script type="text/javascript" src="../../js/comm/editcomm.js"></script>
<script type="text/javascript" src="autherWorksTableEdit.js"></script>
<script type="text/javascript">
		$(function(){
// 			getDataById(root + 'cms/autherWorksTable/findAutherWorksTableById',"#autherWorksTableTmpl","#autherWorksTableContent");
			$("#saveOrupdate").click(function(){
				//封装图片路径 start
				var imgUrls = $('input[name=imgUrl]');
				var urls = "";//拼接后的图片路径
				for (var i = 0; i < imgUrls.length; i++) {
					var imgUrlInput = imgUrls[i];
					var imgUrl = imgUrlInput.value;
					urls += imgUrl + ",";
				}
				urls = urls.substring(0,urls.length-1)
				$('#worksImgs').val(urls);
				//封装图片路径 end
				
				saveData(root + 'cms/autherWorksTable/saveAutherWorksTable','autherWorksTableList.jsp');
			});
			var tId = getUrlParam("id");
			if (!tId) {
				myAlert('id参数不能为空');
				return;
			}
			$.ajax({
				url : root + 'cms/autherWorksTable/findAutherWorksTableById',
				type : 'post',
				dataType : 'json',
				data : {
					modelId : tId
				},
				success : function(data) {
					if (data.code == 1) {
					console.log(data.object)
						var contentHtml = $('#autherWorksTableTmpl').render(data.object, {
							mydata : data
						});
						$('#autherWorksTableContent').html(contentHtml);
						
						//填充数据 start
						var artList = data.object.artList;
						var optionHtml = '';
						for (var i = 0; i < data.object.artList.length; i++) {
							var authorName = artList[i].authorName;
							var id = artList[i].id;
							if(data.object.autherWorksTable.autherID == data.object.artList[i].id ){
								optionHtml += "<option value ='"+id + "' selected>" + authorName + "</option>";
							}else{
								optionHtml += "<option value ='"+id+"'>"+authorName+"</option>";
							}
						}
						$('#autherID').html(optionHtml);
						//填充数据  end
						
						ue = UE.getEditor("worksIntroduce");
						ue.addListener("ready", function() {
							if (data.object.autherWorksTable.worksIntroduce)
								ue.setContent(data.object.autherWorksTable.worksIntroduce);
						});
					}else{
						var contentHtml = $('#autherWorksTableTmpl').render("");
						$('#autherWorksTableContent').html(contentHtml);
					}
				}
			});
		});
</script>
</head>
<body>
	<section>
		<div>
			<div class="col-xs-12">
				<div class="box" style="height:900px">
					<div class="box-header">
						<br> <input type="button" value="确定" id="saveOrupdate"
							class="btn btn-success">
						<input type="button" onclick="backAction('autherWorksTableEdit.jsp');" class="btn btn-info" value="返回"/>
					</div>
					<form id="submit_form" class="form-horizontal">
						<div class="tab" id="autherWorksTableContent"></div>
					</form>
				</div>
			</div>
		</div>
	</section>
	<script type="text/x-jsrender" id="autherWorksTableTmpl">
			<fieldset> 
				<input type="hidden" id="tId" name="id" value="{{:autherWorksTable.id}}" />
	        	{{!--<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">图片：</label>
       				 <div class="col-md-3">
						<div class="upload_div">
                        	<img id="myImageShow" src="../../{{:imgUrl}}" width="100px" height="100px" />
                        	<input type="hidden" id="imgUrl" name="imgUrl" value="{{:imgUrl}}"/>
                        	<input type="file" id="uploadPhotoFile" name="photoFile" class="upload_file">
                        </div>
					</div>
      			</div>--}}
				<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">作品名称：</label>
       				 <div class="col-md-3">
						<input type="text" placeholder="请填写作品名称" class="form-control input-sm" data-rule="required;length[0~50]" id="worksName" name="worksName" value="{{:autherWorksTable.worksName}}" />
					</div>
				</div>
				<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">作者：</label>
       				 <div class="col-md-3">
						<select class="form-control input-sm" id="autherID" name="autherID" data-rule="required" >
						</select>
					</div>
      			</div>
				<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">作品价格：</label>
       				 <div class="col-md-3">
						<input type="text" placeholder="请填写作品价格" class="form-control input-sm" data-rule="required;length[0~50];money" id="worksPrice" name="worksPrice" value="{{:autherWorksTable.worksPrice}}" />
					</div>
      			</div>
      			<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">作品库存：</label>
       				 <div class="col-md-3">
						<input type="text" placeholder="请填写作品库存" class="form-control input-sm" data-rule="required;length[0~50];money" id="worksInventory" name="worksInventory" value="{{:autherWorksTable.worksInventory}}" />
					</div>
      			</div>
				<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">作品定金：</label>
       				 <div class="col-md-3">
						<input type="text" placeholder="请填写作品定金" class="form-control input-sm" data-rule="required;length[0~50];money" id="worksDeposit" name="worksDeposit" value="{{:autherWorksTable.worksDeposit}}" />
					</div>
      			</div>
				<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">排序值：</label>
       				 <div class="col-md-3">
						<input type="text" placeholder="请填写排序值" class="form-control input-sm" data-rule="length[1~10];plus" maxlength="10" id="sort" name="sort" value="{{:sort}}" />
					</div>
      			</div>
				<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">作品图片：</label>
       				 <div class="col-md-9" id="imgDiv">
						{{for worksImgs1}}
							<div class="upload_div" style="float: left; margin-right: 15px;">
								<img id="myImageShow{{:#index+1}}" src="../..{{:}}" width="100px" height="100px" />
								<input type="hidden" id="imgUrl{{:#index+1}}" name="imgUrl" value="{{:}}"/>
								<input type="file" id="uploadPhotoFile{{:#index+1}}" name="photoFile" class="upload_file" data-type="' + type + '">
							</div>
                        {{/for}}
						<input type="hidden" id="worksImgs" name="worksImgs"/>
						<img src="../../image/add.png"  class="add_img" style="cursor:pointer;" data-type="0">
						<img src="../../image/jian.png" class="del_img" style="cursor:pointer;" data-type="0">				
					</div>
      			</div>
				<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">作品简介：</label>
					<div class="col-md-9" id="worksIntroduce" name="worksIntroduce" style="height:200px;"></div>
      			</div>
			</fieldset>
	</script>
</body>
	</html></i>